package com.putao.album.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.putao.album.R;
import com.putao.album.util.ViewHelper;

/**
 * Created by jidongdong on 15/5/7.
 */
public class ShareAppDialogBuilder extends DialogBuilder implements View.OnClickListener {

    private onShareAppChannelListener mOnShareAppChannelListener;

    public ShareAppDialogBuilder setOnShareAppChannelListener(onShareAppChannelListener listener) {
        mOnShareAppChannelListener = listener;
        return this;
    }

    public ShareAppDialogBuilder(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.dialog_pt_share_app_layout;
    }

    @Override
    protected void doInitSubView(View view) {
        LinearLayout ll_qq = ViewHelper.queryViewById(view, R.id.ll_qq);
        LinearLayout ll_chat = ViewHelper.queryViewById(view, R.id.ll_chat);
        LinearLayout ll_sms = ViewHelper.queryViewById(view, R.id.ll_sms);
        if (ll_qq != null)
            ll_qq.setOnClickListener(this);
        if (ll_chat != null)
            ll_chat.setOnClickListener(this);
        if (ll_sms != null)
            ll_sms.setOnClickListener(this);

        //设置底部对齐,边距为0
        Window win = getDialog().getWindow();
        win.setGravity(Gravity.BOTTOM);
        win.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = WindowManager.LayoutParams.FILL_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        win.setAttributes(lp);
    }

    @Override
    protected void setWindowAnim(Dialog dialog) {
//        Window window = dialog.getWindow();
//        window.setWindowAnimations(R.style.dialog_message_style);
    }

    @Override
    protected void doSetupData() {

    }

    @Override
    public void onClick(View v) {
        ShareAppChannel type = null;
        switch (v.getId()) {
            case R.id.ll_chat:
                type = ShareAppChannel.CHAT;
                break;
            case R.id.ll_qq:
                type = ShareAppChannel.QQ;
                break;
            case R.id.ll_sms:
                type = ShareAppChannel.SMS;
                break;
        }
        if (mOnShareAppChannelListener != null) {
            mOnShareAppChannelListener.onShare(getDialog(), type);
        }
    }

    public interface onShareAppChannelListener {
        void onShare(Dialog dialog, ShareAppChannel channel);
    }

    public enum ShareAppChannel {
        QQ,
        CHAT,
        SMS
    }
}
